<?php
namespace StarCloud\Library;

class ArraySort
{
    public static function multiSort(array $data, $order = []): array
    {
        $groupSort = [];
        foreach ($order as $column => $sort) {
            self::isRightSort($sort) && $groupSort[] = [
                array_column($data, $column),
                $sort,
            ];
        }

        foreach ($groupSort as $item) {
            array_multisort($item[0], $item[1], $data);
        }

        return $data;
    }

    private static function isRightSort($sort): bool
    {
        return in_array($sort, [
            SORT_ASC,
            SORT_DESC,
            SORT_REGULAR,
            SORT_NUMERIC,
            SORT_STRING,
            SORT_LOCALE_STRING,
        ]);
    }
}
